{% set os_map = salt['grains.filter_by']({
    'Debian': {
        'pkg_name': 'redis-server',
        'svc_name': 'redis-server',
        'cfg_name': '/etc/redis/redis.conf',
        'cfg_version': salt['grains.filter_by']({
	  'wheezy': '2.4',
	  'jessie': '2.8',
	  'default': '2.8'
	}, grain='oscodename'),
	'logfile': '/var/log/redis/redis-server.log',
        'pidfile': '/var/run/redis/redis-server.pid'
    },
    'RedHat': {
        'pkg_name': 'redis',
        'svc_name': 'redis',
        'cfg_name': '/etc/redis.conf',
        'cfg_version':  salt['grains.filter_by']({
          'CentOS-6': '2.4',
          'CentOS Linux-7': '2.8',
          'default':  '2.4'
         }, grain='osfinger'),
        'logfile': '/var/log/redis/redis.log',
        'pidfile': '/var/run/redis.pid'
    },
		'Arch': {
        'pkg_name': 'redis',
        'svc_name': 'redis',
        'cfg_name': '/etc/redis.conf',
        'cfg_version': '3.0',
        'logfile': '/var/log/redis/redis.log',
        'pidfile': '/var/run/redis.pid'
    },
}, merge=salt['pillar.get']('redis:lookup')) %}

{% set default_settings = {
    'redis': {
        'appendfilename': 'appendonly.aof',
        'appendonly': 'no',
        'appendfsync': 'everysec',
        'auto_aof_rewrite_min_size': '64mb',
        'auto_aof_rewrite_percentage': 100,
        'aof_load_truncated': 'yes',
        'bin': '/usr/local/bin/redis-server',
        'bind': '127.0.0.1',
        'database_count': 16,
        'root_dir': '/var/lib/redis',
        'dbfilename': 'dump.rdb',
        'daemonize': 'yes',
        'group': 'redis',
        'home': '/var/lib/redis',
        'install_from': 'package',
        'latency_monitor_threshold': 0,
        'loglevel': 'notice',
        'lua_time_limit': 5000,
        'maxmemory_policy': 'volatile-lru',
        'maxmemory_samples': 3,
        'notify_keyspace_events': '""',
        'no_appendfsync_on_rewrite': 'no',
        'port': 6379,
        'rdbchecksum': 'yes',
        'rdbcompression': 'yes',
        'repl_disable_tcp_nodelay': 'no',
        'slave_priority': 100,
        'slave_read_only': 'yes',
        'repl_diskless_sync': 'no',
        'repl_diskless_sync_delay': 5,
        'slave_serve_stale_data': 'yes',
        'slowlog_max_len': 128,
        'slowlog_log_slower_than': 10000,
        'snapshots': [
            '900 1',
            '300 10',
            '60 10000'
            ],
        'stop_writes_on_bgsave_error': 'yes',
        'svc_onboot': True,
        'svc_state': 'running',
        'timeout': 0,
        'tcp_backlog': 511,
        'tcp_keepalive': 0,
        'unixsocketperm': 755,
        'user': 'redis'
	}
}%}

{# Merge os_map into default_settings dictionary #}
{% do default_settings.redis.update(os_map) %}

{# Update settings defaults from pillar data #}
{% set redis_settings = salt['pillar.get']('redis', default=default_settings.redis,
  merge=True) %}
